var express =require('express')

//创建子路由对象
var tewRouter=express.Router()


 tewRouter.get('/list', (req, res) => {
    var { page, count } = req.query
    var newarr = arr.slice((page - 1) * count, page * count)
    res.send({ code: 200, msg: '请求成功', list: newarr })
})
//模糊查询
 tewRouter.get('/search', (req, res) => {
    var { searchkey } = req.query
    var newarr = arr.filter((item) => {
        return new RegExp(searchkey).test(item.name)
    })
    res.send({ code: 200, msg: '请求成功', list: newarr })
})

//登陆
 tewRouter.post('/login', (req, res) => {
    var { phone, pass } = req.body
    console.log('收到来自服务器端的请求');
    console.log(phone, pass);
    var i = arr.findIndex((item) => {
        return item.phone == phone && item.pass == pass
    })
    if (i != -1) {
        res.send({ code: 200, msg: '登陆成功', list: arr[i] })
    } else {
        res.send({ code: 400, msg: '登陆失败' })

    }


})
